import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;


import java.util.ArrayList;
import java.util.Arrays;

class MyException1 extends Exception {};
class MyException2 extends Exception {};



/**
 * Klasa PlayerThread umozliwia polaczenie sie wielu klientow z serwerem
 * @author ubuntu
 *
 */


public class PlayerThread implements Runnable {
		
		int personalNumber;
		BufferedReader in = null;
		PrintWriter out = null;
		Socket client = null;
		SocketServer server = null;
		String line = "";  //line bedzie jako RozkladArgs do metody RozkladLiczbyTest
		String answer = "ANSWER";
		
		
		
		public PlayerThread (SocketServer s, Socket socket, String name) {
			server = s;
			client = socket;
			System.out.println("Name of the Thread: " + name);
			try {
				in = new BufferedReader(new InputStreamReader(
						client.getInputStream()));
				out = new PrintWriter(client.getOutputStream(), true);
			}
			catch (IOException e) {
				System.out.println("i/o");
			}
		}
		
		public void run() {
			
			try {
				in = new BufferedReader(new InputStreamReader(
						client.getInputStream()));
				out = new PrintWriter(client.getOutputStream(), true);
			}
			catch (IOException e) {
				System.out.println("i/o");
			}
			while (line != null) {
				try {
					line = in.readLine();
					if (Character.toString(line.charAt(0)) == null) {
						System.out.println("Zerwano polaczenie");
					
					}
					//recognizeQuestion(line);
					
					
					System.out.println(line + "  ---->  " + answer );
					out.println("Cokolwiek");
					if (line == null) break; // mozna dodac, && line == 'Q' <- sygnal konca
					
					
				} catch (IOException e) {
					System.out.println("Read line");
				} catch (NumberFormatException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 			
			}
		}
		
}
